﻿using System;
using System.Threading;



namespace Bubble
{
    class Program
    {
        static Player player;
        static Field field;
        static Random next = new Random();

        static void Main()
        {
            // като начало може да напишен start in 3->2->1
            // ако искаме да си усложним живота може да имаме символ който ако бъде ударен да гръмва с някакъв радиус
            // да помислим за цветове на числата
            //пъвроначално положение на курсор
            StartScreen();


            //int level = 0;
            //StartGame(level);
            //Console.ReadLine();
        }

        private static void StartScreen()
        {
            int n = 7;

            int heigth = n;
            int column = 0;
            int time = 1000;

            //print 1
            heigth += n;
            column += 0;
            Print3(n, heigth, column);
            Thread.Sleep(time);
            Console.Clear();

            //print2
            //heigth -= 2 * n;10
            // +=  n / 2;
            Print2(n, heigth, column);
            Thread.Sleep(time);
            Console.Clear();

            //print 3
            Print1(n, heigth, column);
            Thread.Sleep(time);
            Console.Clear();


            // printing S
            heigth = 0;
            column = n;
            PrintS(n, heigth, column);

            ////print T
            heigth += n;
            column += 0;
            PrintT(n, heigth, column);

            //// printing a
            heigth += n;
            column += 0;
            PrintA(n, heigth, column);
            // printing r
            heigth += n;
            column += 0;
            PrintR(n, heigth, column);
            ////print T
            heigth += n;
            column += 0;
            PrintT(n, heigth, column);
            Thread.Sleep(2 * time);
            Console.Clear();


            heigth -= 3 * n;
            Console.SetCursorPosition(heigth, column);
            Console.WriteLine("PLEASE CHOOSE LEVEL FROM 1 TO 10");
            Thread.Sleep(time * 3);
            //Console.Clear();
            column++;
            Console.SetCursorPosition(heigth, column);
            Console.Write("PLEASE ENTER LEVEL: ");
            try
            {
                int level = int.Parse(Console.ReadLine());
                if (level < 1 || level > 10)
                {
                    column++;

                    Console.SetCursorPosition(heigth, column);

                    throw new ArgumentException();
                }
            }
            catch (ArgumentException)
            {
                column++;

                Console.SetCursorPosition(heigth, column++);
                column++;

                Console.Write("NO SUCH LEVEL!");
                Console.SetCursorPosition(heigth, column++);

                Console.Write("PLEASE ENTER LEVEL: ");
                int level = int.Parse(Console.ReadLine());
                column++;

                Console.SetCursorPosition(heigth, column++);

            }
        }

        private static void StartGame(int level)
        {
            player = new Player(20, 20, level);
            field = new Field(20, 20, 0);

            int count = 0;

            //StartScreen

            player.Print();
            field.Print();
            while (true)
            {
                if (player.MovePlayer())
                {
                    if (player.isShoot)
                    {
                        Console.Clear();
                        player.isShoot = false;
                        player.Points += field.PutNewSymbol(player.Col, player.LastSymbol);
                        field.Print();
                    }
                    player.Print();
                }

                if (count == player.level)
                {
                    field.AddNewLine();
                    field.Print();
                    player.Print();
                    count = 0;
                }
                // матрицата да достига row-1 иначе има доблиране и човек се чуди какво става 
                if (field.isEndGame)
                {
                    //EndScreen  Калоян
                    //
                    Console.WriteLine("END");
                    Console.ReadLine();

                    // да помислим за по-грандиозен END - МЯСТО ВИЗИЯ 
                    Console.Clear();
                    Console.WriteLine("END");
                    break;


                }
                count++;
                Thread.Sleep(100);
            }
        }

        private static void Print3(int n, int heigth, int column)
        {
            string[,] matrix = new string[n, (n - 2)];

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    if (((row == 0 || row == n / 2 || row == matrix.GetLength(0) - 1) && (col >= 0 && col < matrix.GetLength(1) - 1)) ||
                        (col == matrix.GetLength(1) - 1 && ((row > 0 && row < n / 2) || (row > n / 2 && row < matrix.GetLength(0) - 1))))
                    {
                        int num = next.Next(0, 10);
                        Console.Write(num);
                    }
                    else
                    {
                        Console.Write(" ");
                    }

                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }

        private static void Print2(int n, int heigth, int column)
        {
            string[,] matrix = new string[n, (n - 2)];

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    if (((row == 0 || row == n / 2 ||
                        row == matrix.GetLength(0) - 1) && (col > 0 && col < matrix.GetLength(1) - 1)) ||
                        (col == matrix.GetLength(1) - 1 && row > 0 && row < n / 2) ||
                        (col == 0 && row < matrix.GetLength(0) - 1 && row > n / 2))
                    {
                        int num = next.Next(0, 10);
                        Console.Write(num);
                    }
                    else
                    {
                        Console.Write(" ");
                    }

                }
                Console.WriteLine();
            }
            Console.WriteLine();

        }

        private static void Print1(int n, int heigth, int column)
        {
            string[,] matrix = new string[n, (n - 2)];

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    if ((row >= 0 && row < matrix.GetLength(0)) && col == matrix.GetLength(1) / 2)
                    {
                        int num = next.Next(0, 10);
                        Console.Write(num);
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
        static void PrintS(int n, int heigth, int column)
        {
            string[,] matrix = new string[n, (n - 2)];

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    if (((row == 0 || row == n / 2 || row == matrix.GetLength(0) - 1) && (col > 0 && col < matrix.GetLength(1) - 1)) || (col == 0 && row > 0 && row < n / 2) || (col == matrix.GetLength(1) - 1 && row < matrix.GetLength(0) - 1 && row > n / 2))
                    {
                        int num = next.Next(0, 10);
                        Console.Write(num);
                    }
                    else
                    {
                        Console.Write(" ");
                    }

                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
        static void PrintT(int n, int heigth, int column)
        {
            string[,] matrix = new string[n, (n - 2)];

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    if (row == 0 || col == (n - 2) / 2)
                    {
                        int num = next.Next(0, 10);
                        Console.Write(num);
                    }
                    else
                    {
                        Console.Write(" ");
                    }

                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }

        static void PrintA(int n, int heigth, int column)
        {
            string[,] matrix = new string[n, (n - 2)];

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    if (row + col == (n - 2) / 2 || col - row == (n - 2) / 2 || (col == 0 && row >= n / 2) || (col == matrix.GetLength(1) - 1 && row >= n / 2) || row == n / 2)
                    {
                        int num = next.Next(0, 10);
                        Console.Write(num);
                    }
                    else
                    {
                        Console.Write(" ");
                    }

                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }

        static void PrintR(int n, int heigth, int column)
        {
            string[,] matrix = new string[n, (n - 2)];

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    if (col == 0 || ((row == 0 || row == n / 2) && col < matrix.GetLength(1) - 1) || (col == matrix.GetLength(1) - 1 && row >= 1 && row < n / 2) || (row > n / 2 && col >= (n - 2) / 2 && row - col == 2))
                    {
                        int num = next.Next(0, 10);
                        Console.Write(num);
                    }
                    else
                    {
                        Console.Write(" ");
                    }

                }
                Console.WriteLine();
            }
            Console.WriteLine();

        }
    }
}
